﻿@model FieldControlViewModel
@{
	string ToolbarSet = string.Empty;
	//switch (Model.Settings[0])
	//{
	//	case "0":
	//		ToolbarSet = ",toolbars: [['fullscreen', 'source', 'undo', 'redo', 'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc']]";
	//		break;
	//	default:
	//		ToolbarSet = string.Empty;
	//		break;
	//}
	string dataVal = string.Empty;
	string dataValMsg = string.Empty;
	if (Model.EnableNull)
	{
		dataVal += " data-val-required=\"不能为空\" ";
	}
	if (!string.IsNullOrEmpty(dataVal))
	{
		dataVal += " data-val=\"true\" ";
		dataValMsg = " data-valmsg-for=\"" + Model.Prefix + Model.FieldName + "\" data-valmsg-replace=\"true\"";
	}
}
<textarea name="@Model.Prefix@Model.FieldName" id="@Model.Prefix@Model.FieldName" value="@Model.FieldValue" @Html.Raw(dataVal)></textarea>
<span class="layui-bg-green">@Model.Description</span>
<span style="color:red;" @Html.Raw(dataValMsg)></span>

<script type="text/javascript">
	var ue@{@Model.Prefix@Model.FieldName} = UE.getEditor('@{@Model.Prefix@Model.FieldName}', {
		autoHeight: true
		, disabledTableInTable: false
		@Html.Raw(ToolbarSet)
	});
	//对编辑器的操作最好在编辑器ready之后再做
	ue@{@Model.Prefix@Model.FieldName}.ready(function () {
		//设置编辑器的内容
		var htmlUE = "@Html.Raw(!(string.IsNullOrWhiteSpace(Model.FieldValue))? Model.FieldValue.Replace("\r\n", "").Replace("\"", "\\\""):"")";
		if (htmlUE != "") {
			ue@{@Model.Prefix@Model.FieldName}.setContent(htmlUE);
		}
		var ctlUE = $("textarea[name='@{@Model.Prefix@Model.FieldName}']");
		ctlUE.show();
		ctlUE.css("width", "0px").css("height", "0px").css("position", "absolute").css("z-index", "-1");
	});
</script>
